<?php
/**
 * 用户注册邮件激活处理
 * @author Ice <iceinto@mallog.com.cn>
 */
class RegisterMailModel extends BaseModel
{
	/**
	 * 添加注册邮件信箱
	 * @param string $email
	 * @param string $key
	 * @author Ice <iceinto@mallog.com.cn>
	 */
	public function addRMail($email, $key, $uid = 0){
		$data = array();
		$data = $this->find($email);
		if($data){
			$data['update_time'] = time();
			$data['update_ip'] = get_client_ip();
			return $this->save($data);
		}else{
			$time = time();
			$ip = get_client_ip();
			$data['email'] = $email;
			$data['key'] = $key;
			$data['create_time'] = $time;
			$data['create_ip'] = $ip;
			$data['update_time'] = $time;
			$data['update_ip'] = $ip;
            $data['uid'] = $uid;
			return $this->add($data);
		}
		return false;
	}

	/**
	 * 获取是否有邮件发送消息还没有过时
	 * @param string $email
	 * @author Ice <iceinto@mallog.com.cn>
	 */
	public function getIsExpired($email){
		$isExp = true;
		$data = $this->find($email);
		if($data){
			$time = time() - 60 * 5;
			if($data['create_time'] > $time){
				$isExp = false;
			}
		}
		return $isExp;
	}

	/**
	 * 激活账号
	 * @param string $email
	 * @author Ice <iceinto@mallog.com.cn>
	 */
	public function activation($email){
		$data = array();
		$data['email'] = $email;
		$data['activation_time'] = time();
		$data['activation_ip'] = get_client_ip();
		return $this->save($data);
	}
}
?>